from odoo import api, fields, models


class BAD(models.Model):
    _name = 'bad.event'
    _description = '药品群体不良事件基本信息表'
    event_no = fields.Char(
        '死亡事件编号',
        index=True,
        readonly=True,
        default='自动生成'
    )

    @api.model
    def create(self, vals):
        """
        自动生成单号
        :return:
        """
        vals['event_no'] = self.env['ir.sequence'].next_by_code('bad.event') or ''
        return super(BAD, self).create(vals)

    area = fields.Char(
        string='发生地区', required=True
    )
    use_unit = fields.Many2one(
        'vaccine.organization',
        string='使用单位',
        required=True
    )
    use_num = fields.Integer(
        string='使用人数', required=True
    )
    have_bad_num = fields.Integer(
        string='发生不良事件人数', required=True
    )
    very_bad_num = fields.Integer(
        string='发生严重不良事件人数', required=True
    )
    dead_num = fields.Integer(
        string='死亡人数', required=True
    )
    use_date = fields.Date(
        string='首例用药日期', required=True
    )
    happend_date = fields.Date(
        string='首例发生日期', required=True
    )
    question_drug = fields.Many2many(
        'vaccine.information.entering', string='怀疑药品', required=True
    )
    facilities = fields.Many2many(
        'instrument.base', string='器械'
    )
    reaction = fields.Text(
        string='不良事件表现', required=True
    )
    reaction_process = fields.Html(
        string='群体不良事件过程描述及处理情况(可附页)', required=True
    )
    advice = fields.Text(
        string='报告单位意见', required=True
    )
    person = fields.Many2one(
        'res.users',
        string='报告人',
        required=True
    )
    tel = fields.Char(
        related='person.mobile',
        readonly=True,
        string='报告人电话',
        store=True
    )
    email = fields.Char(
        related='person.login',
        readonly=True,
        string='报告人电子邮箱',
        store=True
    )
    name = fields.Char(
        default='药品群体不良事件基本信息表详情'
    )
    report_unit = fields.Many2many(
        'factory',
        string='报告单位信息'
    )
    report_date = fields.Date(
        string='报告日期',
        default=lambda self: fields.Date.today(),
        required=True
    )
